<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>计算机网络课设——UDP/TCP/TLS Socket实验 | Mox的笔记库</title><meta name="keywords" content="Working"><meta name="author" content="MocusEZ"><meta name="copyright" content="MocusEZ"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Socket聊天实验室">
<meta property="og:type" content="article">
<meta property="og:title" content="计算机网络课设——UDP&#x2F;TCP&#x2F;TLS Socket实验">
<meta property="og:url" content="https://www.mocusez.site/posts/5e44.html">
<meta property="og:site_name" content="Mox的笔记库">
<meta property="og:description" content="Socket聊天实验室">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://s1.ax1x.com/2023/09/09/pP6qXOU.png">
<meta property="article:published_time" content="2023-09-09T07:10:00.000Z">
<meta property="article:modified_time" content="2023-09-09T07:10:00.000Z">
<meta property="article:author" content="MocusEZ">
<meta property="article:tag" content="Working">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://s1.ax1x.com/2023/09/09/pP6qXOU.png"><link rel="shortcut icon" href="/img/title.jpg"><link rel="canonical" href="https://www.mocusez.site/posts/5e44"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?c85c9eaebc158345532b86397a6dded9";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '计算机网络课设——UDP/TCP/TLS Socket实验',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-09-09 15:10:00'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.2.0"><link rel="alternate" href="/atom.xml" title="Mox的笔记库" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/head.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">61</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链&amp;私人收藏</span></a></div><div class="menus_item"><a class="site-page" href="/board/"><i class="fa-fw fas fa-user"></i><span> 留言板</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://s1.ax1x.com/2023/09/09/pP6qXOU.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Mox的笔记库</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链&amp;私人收藏</span></a></div><div class="menus_item"><a class="site-page" href="/board/"><i class="fa-fw fas fa-user"></i><span> 留言板</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">计算机网络课设——UDP/TCP/TLS Socket实验</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-09-09T07:10:00.000Z" title="发表于 2023-09-09 15:10:00">2023-09-09</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-09-09T07:10:00.000Z" title="更新于 2023-09-09 15:10:00">2023-09-09</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%97%A5%E5%B8%B8%E7%AC%94%E8%AE%B0/">日常笔记</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="计算机网络课设——UDP/TCP/TLS Socket实验"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="计算机网络课设——UDP-x2F-TCP-x2F-TLS-Socket实验"><a href="#计算机网络课设——UDP-x2F-TCP-x2F-TLS-Socket实验" class="headerlink" title="计算机网络课设——UDP&#x2F;TCP&#x2F;TLS Socket实验"></a>计算机网络课设——UDP&#x2F;TCP&#x2F;TLS Socket实验</h1><p>2022年11月整的活儿。我看周围的人去网上去抄一篇C&#x2F;C++&#x2F;Java的Socket聊天实验室基本就能很好的把作业交差了，而我则选择用刚学的Go写一个用TLS加密Socket实验室。这几天整理了以下当时的代码，用GPT4生成使用TCP，UDP，TLS的Socker服务，重新温习一下Go语言的的操作。</p>
<h2 id="TCP"><a href="#TCP" class="headerlink" title="TCP"></a>TCP</h2><p>tcp_server.go</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">package main <span class="comment">// 声明main包</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> ( <span class="comment">// 导入需要的包</span></span><br><span class="line">	<span class="string">&quot;bufio&quot;</span> <span class="comment">// 带缓冲的IO操作包</span></span><br><span class="line">	<span class="string">&quot;fmt&quot;</span> <span class="comment">// 格式化和打印</span></span><br><span class="line">	<span class="string">&quot;net&quot;</span> <span class="comment">// 网络操作包</span></span><br><span class="line">	<span class="string">&quot;strings&quot;</span> <span class="comment">// 字符串操作包</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">func <span class="title function_">main</span>(<span class="params"></span>) &#123; <span class="comment">// 主函数</span></span><br><span class="line"></span><br><span class="line">	fmt.<span class="title class_">Println</span>(<span class="string">&quot;Starting server...&quot;</span>) <span class="comment">// 打印启动服务器的信息</span></span><br><span class="line"></span><br><span class="line">	listener, _ := net.<span class="title class_">Listen</span>(<span class="string">&quot;tcp&quot;</span>, <span class="string">&quot;:8080&quot;</span>) <span class="comment">// 监听8080端口</span></span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> &#123; <span class="comment">// 无限循环 保持服务器运行</span></span><br><span class="line">		conn, _ := listener.<span class="title class_">Accept</span>() <span class="comment">// 接收新的连接</span></span><br><span class="line">		go <span class="title function_">handleRequest</span>(conn) <span class="comment">// 单独的goroutine处理连接</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">func <span class="title function_">handleRequest</span>(<span class="params">conn net.Conn</span>) &#123; <span class="comment">// 处理请求的函数</span></span><br><span class="line"></span><br><span class="line">	defer conn.<span class="title class_">Close</span>() <span class="comment">// 函数结束时关闭连接</span></span><br><span class="line"></span><br><span class="line">	reader := bufio.<span class="title class_">NewReader</span>(conn) <span class="comment">// 从连接中读取</span></span><br><span class="line">	message, _ := reader.<span class="title class_">ReadString</span>(<span class="string">&#x27;\n&#x27;</span>) <span class="comment">// 读取字符串直到\n</span></span><br><span class="line">	message = strings.<span class="title class_">TrimSpace</span>(message) <span class="comment">// 去掉字符串两边的空格</span></span><br><span class="line"></span><br><span class="line">	fmt.<span class="title class_">Printf</span>(<span class="string">&quot;Received: %s\n&quot;</span>, message) <span class="comment">// 打印接收到的消息</span></span><br><span class="line"></span><br><span class="line">	conn.<span class="title class_">Write</span>([]<span class="title function_">byte</span>(<span class="string">&quot;Message received.\n&quot;</span>)) <span class="comment">// 响应客户端</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>一个简单的TCP Socket Server，不涉及对conn的存储</p>
<p>聊天室需要利用对conn的存储进行实现</p>
<h2 id="UDP"><a href="#UDP" class="headerlink" title="UDP"></a>UDP</h2><p>udp_server.go</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main <span class="comment">// 声明main包</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">    <span class="string">&quot;fmt&quot;</span> <span class="comment">// 格式化和打印输出</span></span><br><span class="line">    <span class="string">&quot;net&quot;</span> <span class="comment">// 网络操作包</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line"></span><br><span class="line">    p := <span class="built_in">make</span>([]<span class="type">byte</span>, <span class="number">2048</span>) <span class="comment">// 创建一个2048字节的缓冲区</span></span><br><span class="line"></span><br><span class="line">    addr := net.UDPAddr&#123; </span><br><span class="line">        Port: <span class="number">12345</span>, <span class="comment">// 监听端口</span></span><br><span class="line">        IP:   net.ParseIP(<span class="string">&quot;127.0.0.1&quot;</span>), <span class="comment">// 监听接口 </span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    ser, err := net.ListenUDP(<span class="string">&quot;udp&quot;</span>, &amp;addr) <span class="comment">// 监听UDP端口</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        fmt.Printf(<span class="string">&quot;Some error %v&quot;</span>, err) <span class="comment">// 如果监听失败,打印错误</span></span><br><span class="line">        <span class="keyword">return</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> &#123; <span class="comment">// 无限循环,持续监听</span></span><br><span class="line"></span><br><span class="line">        _, remoteaddr, err := ser.ReadFromUDP(p) <span class="comment">// 读取一个UDP数据报文</span></span><br><span class="line"></span><br><span class="line">        fmt.Printf(<span class="string">&quot;Read a message from %v %s \n&quot;</span>, remoteaddr, p) <span class="comment">// 打印客户端地址和内容</span></span><br><span class="line"></span><br><span class="line">        <span class="keyword">if</span> err != <span class="literal">nil</span> &#123; <span class="comment">// 如果读取失败</span></span><br><span class="line">            fmt.Printf(<span class="string">&quot;Some error %v&quot;</span>, err)</span><br><span class="line">            <span class="keyword">continue</span></span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">go</span> sendResponse(ser, remoteaddr) <span class="comment">// 开启goroutine回复客户端</span></span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">sendResponse</span><span class="params">(conn *net.UDPConn, addr *net.UDPAddr)</span></span> &#123;</span><br><span class="line"></span><br><span class="line">    _, err := conn.WriteToUDP([]<span class="type">byte</span>(<span class="string">&quot;From server: Hello I got your mesage &quot;</span>), addr) <span class="comment">//回复客户端</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">        fmt.Printf(<span class="string">&quot;Couldn&#x27;t send response %v&quot;</span>, err) <span class="comment">// 如果回复失败,打印错误</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>udp_client.go</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">go run udp_client.go 127.0.0.1:12345</span><br></pre></td></tr></table></figure>



<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;fmt&quot;</span> <span class="comment">// 格式化和打印输出包</span></span><br><span class="line">	<span class="string">&quot;net&quot;</span> <span class="comment">// 网络操作包</span></span><br><span class="line">	<span class="string">&quot;os&quot;</span>   <span class="comment">// 操作系统功能包</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">	</span><br><span class="line">	<span class="keyword">if</span> <span class="built_in">len</span>(os.Args) != <span class="number">2</span> &#123; <span class="comment">// 检查命令行参数数量</span></span><br><span class="line">		fmt.Fprintf(os.Stderr, <span class="string">&quot;Usage: %s host:port&quot;</span>, os.Args[<span class="number">0</span>]) <span class="comment">// 打印使用说明</span></span><br><span class="line">		os.Exit(<span class="number">1</span>) <span class="comment">// 退出程序</span></span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	service := os.Args[<span class="number">1</span>] <span class="comment">// 获取服务地址</span></span><br><span class="line">	</span><br><span class="line">	udpAddr, err := net.ResolveUDPAddr(<span class="string">&quot;udp4&quot;</span>, service) <span class="comment">// 解析UDP地址</span></span><br><span class="line">	CheckError(err) <span class="comment">// 检查错误</span></span><br><span class="line">	</span><br><span class="line">	conn, err := net.DialUDP(<span class="string">&quot;udp&quot;</span>, <span class="literal">nil</span>, udpAddr) <span class="comment">// 拨号UDP服务</span></span><br><span class="line">	CheckError(err) <span class="comment">// 检查错误</span></span><br><span class="line">	</span><br><span class="line">	<span class="keyword">defer</span> conn.Close() <span class="comment">// 函数结束时关闭连接</span></span><br><span class="line">	</span><br><span class="line">	_, err = conn.Write([]<span class="type">byte</span>(<span class="string">&quot;Hello from client&quot;</span>)) <span class="comment">// 发送数据</span></span><br><span class="line">	CheckError(err) <span class="comment">// 检查错误</span></span><br><span class="line">	</span><br><span class="line">	<span class="keyword">var</span> buf [<span class="number">512</span>]<span class="type">byte</span> <span class="comment">// 创建512字节缓冲区</span></span><br><span class="line">	n, err := conn.Read(buf[<span class="number">0</span>:]) <span class="comment">// 读取数据</span></span><br><span class="line">	CheckError(err) <span class="comment">// 检查错误</span></span><br><span class="line">	</span><br><span class="line">	fmt.Println(<span class="type">string</span>(buf[<span class="number">0</span>:n])) <span class="comment">// 打印接收到的数据</span></span><br><span class="line">	</span><br><span class="line">	os.Exit(<span class="number">0</span>) <span class="comment">// 正常退出</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">CheckError</span><span class="params">(err <span class="type">error</span>)</span></span> &#123; <span class="comment">// 错误检查函数</span></span><br><span class="line">	<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">		fmt.Fprintf(os.Stderr, <span class="string">&quot;Fatal error: %s&quot;</span>, err.Error())</span><br><span class="line">		os.Exit(<span class="number">1</span>)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="TLS"><a href="#TLS" class="headerlink" title="TLS"></a>TLS</h2><p>先用OpenSSL生成公钥和私钥证书</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 1. 生成私钥</span></span><br><span class="line">openssl genrsa -out private.key 2048</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2. 基于私钥生成证书签名请求(CSR)</span></span><br><span class="line">openssl req -new -key private.key -out cert.csr</span><br><span class="line"></span><br><span class="line"><span class="comment"># 3. 生成自签名证书</span></span><br><span class="line">openssl x509 -req -days 365 -<span class="keyword">in</span> cert.csr -signkey private.key -out cert.crt</span><br><span class="line"></span><br><span class="line"><span class="comment"># 4. 查看证书内容</span></span><br><span class="line">openssl x509 -<span class="keyword">in</span> cert.crt -text -noout</span><br></pre></td></tr></table></figure>

<p>转成pem文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 私钥</span></span><br><span class="line">openssl pkcs8 -topk8 -inform PEM -<span class="keyword">in</span> private.key -out private.pem -nocrypt</span><br><span class="line"></span><br><span class="line"><span class="comment"># 证书 </span></span><br><span class="line">openssl x509 -<span class="keyword">in</span> cert.crt -out cert.pem -outform PEM</span><br></pre></td></tr></table></figure>

<p>用Claude 2和GPT4都没有生成可用的代码，最后用ChatGPT生成了下面代码</p>
<p>tls_server.go</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;crypto/tls&quot;</span></span><br><span class="line">	<span class="string">&quot;fmt&quot;</span></span><br><span class="line">	<span class="string">&quot;io&quot;</span></span><br><span class="line">	<span class="string">&quot;log&quot;</span></span><br><span class="line">	<span class="string">&quot;net&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">handleConnection</span><span class="params">(conn net.Conn)</span></span> &#123;</span><br><span class="line">	<span class="keyword">defer</span> conn.Close()</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 在这里处理连接</span></span><br><span class="line">	buf := <span class="built_in">make</span>([]<span class="type">byte</span>, <span class="number">1024</span>)</span><br><span class="line">	<span class="keyword">for</span> &#123;</span><br><span class="line">		n, err := conn.Read(buf)</span><br><span class="line">		<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">			<span class="keyword">if</span> err != io.EOF &#123;</span><br><span class="line">				fmt.Println(<span class="string">&quot;读取错误:&quot;</span>, err)</span><br><span class="line">			&#125;</span><br><span class="line">			<span class="keyword">break</span></span><br><span class="line">		&#125;</span><br><span class="line">		fmt.Printf(<span class="string">&quot;收到消息：%s\n&quot;</span>, <span class="type">string</span>(buf[:n]))</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">	<span class="comment">// 加载服务器证书和私钥</span></span><br><span class="line">	cert, err := tls.LoadX509KeyPair(<span class="string">&quot;cert.pem&quot;</span>, <span class="string">&quot;key.pem&quot;</span>)</span><br><span class="line">	<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">		log.Fatal(<span class="string">&quot;加载证书失败：&quot;</span>, err)</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 创建TLS配置</span></span><br><span class="line">	config := &amp;tls.Config&#123;</span><br><span class="line">		Certificates: []tls.Certificate&#123;cert&#125;,</span><br><span class="line">		<span class="comment">// Rand:         rand.Reader,</span></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 创建监听器</span></span><br><span class="line">	listener, err := tls.Listen(<span class="string">&quot;tcp&quot;</span>, <span class="string">&quot;:443&quot;</span>, config)</span><br><span class="line">	<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">		log.Fatal(<span class="string">&quot;监听失败：&quot;</span>, err)</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">defer</span> listener.Close()</span><br><span class="line"></span><br><span class="line">	fmt.Println(<span class="string">&quot;等待客户端连接...&quot;</span>)</span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> &#123;</span><br><span class="line">		<span class="comment">// 接受连接并处理</span></span><br><span class="line">		conn, err := listener.Accept()</span><br><span class="line">		<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">			log.Fatal(<span class="string">&quot;接受连接失败：&quot;</span>, err)</span><br><span class="line">		&#125;</span><br><span class="line">		fmt.Println(<span class="string">&quot;客户端已连接：&quot;</span>, conn.RemoteAddr())</span><br><span class="line"></span><br><span class="line">		<span class="keyword">go</span> handleConnection(conn)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>tls_client.go</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> main</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> (</span><br><span class="line">	<span class="string">&quot;crypto/tls&quot;</span></span><br><span class="line">	<span class="string">&quot;fmt&quot;</span></span><br><span class="line">	<span class="string">&quot;log&quot;</span></span><br><span class="line">	<span class="string">&quot;os&quot;</span></span><br><span class="line">	<span class="string">&quot;os/signal&quot;</span></span><br><span class="line">	<span class="string">&quot;syscall&quot;</span></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">main</span><span class="params">()</span></span> &#123;</span><br><span class="line">	<span class="comment">// 加载客户端证书和私钥</span></span><br><span class="line">	cert, err := tls.LoadX509KeyPair(<span class="string">&quot;cert.pem&quot;</span>, <span class="string">&quot;key.pem&quot;</span>)</span><br><span class="line">	<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">		log.Fatal(<span class="string">&quot;加载证书失败：&quot;</span>, err)</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 创建TLS配置</span></span><br><span class="line">	config := &amp;tls.Config&#123;</span><br><span class="line">		Certificates:       []tls.Certificate&#123;cert&#125;,</span><br><span class="line">		InsecureSkipVerify: <span class="literal">true</span>, <span class="comment">// 忽略服务器端证书验证（仅用于示例，请勿在生产环境中使用）</span></span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 连接服务器</span></span><br><span class="line">	conn, err := tls.Dial(<span class="string">&quot;tcp&quot;</span>, <span class="string">&quot;127.0.0.1:443&quot;</span>, config)</span><br><span class="line">	<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">		log.Fatal(<span class="string">&quot;连接服务器失败：&quot;</span>, err)</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">defer</span> conn.Close()</span><br><span class="line"></span><br><span class="line">	fmt.Println(<span class="string">&quot;已连接到服务器。可以开始发送消息了。&quot;</span>)</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 启动信号监听器以便优雅地关闭连接</span></span><br><span class="line">	<span class="keyword">go</span> <span class="function"><span class="keyword">func</span><span class="params">()</span></span> &#123;</span><br><span class="line">		sigCh := <span class="built_in">make</span>(<span class="keyword">chan</span> os.Signal, <span class="number">1</span>)</span><br><span class="line">		signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)</span><br><span class="line">		&lt;-sigCh</span><br><span class="line"></span><br><span class="line">		fmt.Println(<span class="string">&quot;收到退出信号。关闭连接...&quot;</span>)</span><br><span class="line">		conn.Close()</span><br><span class="line">	&#125;()</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 处理用户输入并发送消息</span></span><br><span class="line">	buf := <span class="built_in">make</span>([]<span class="type">byte</span>, <span class="number">1024</span>)</span><br><span class="line">	<span class="keyword">for</span> &#123;</span><br><span class="line">		n, err := os.Stdin.Read(buf)</span><br><span class="line">		<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">			log.Fatal(<span class="string">&quot;读取输入错误：&quot;</span>, err)</span><br><span class="line">		&#125;</span><br><span class="line">		_, err = conn.Write(buf[:n])</span><br><span class="line">		<span class="keyword">if</span> err != <span class="literal">nil</span> &#123;</span><br><span class="line">			log.Fatal(<span class="string">&quot;发送消息失败：&quot;</span>, err)</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p>抓出来的包不是TLS</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://imgse.com/i/pP6q2SP"><img src="https://s1.ax1x.com/2023/09/09/pP6q2SP.md.png" alt="pP6q2SP.md.png"></a></p>
<p>但内容确实是加密的</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://imgse.com/i/pP6qRQf"><img src="https://s1.ax1x.com/2023/09/09/pP6qRQf.md.png" alt="pP6qRQf.md.png"></a></p>
<p>与纯TCP的连接做个对照</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://imgse.com/i/pP6qfOS"><img src="https://s1.ax1x.com/2023/09/09/pP6qfOS.png" alt="pP6qfOS.png"></a></p>
<p>但我手头上的最早的网络实验里，Wireshark可以找到TLS的握手包</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://imgse.com/i/pP6q5wQ"><img src="https://s1.ax1x.com/2023/09/09/pP6q5wQ.md.png" alt="pP6q5wQ.md.png"></a></p>
<p>然后第二天早上在跑一遍ChatGPT写的程序，TLS1.3就被识别出来了</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://imgse.com/i/pP6q4eg"><img src="https://s1.ax1x.com/2023/09/09/pP6q4eg.md.png" alt="pP6q4eg.md.png"></a></p>
<p>所以这个乌龙应该是Wireshark在IPv6上抓包引起的</p>
<h3 id="Wireshark解密"><a href="#Wireshark解密" class="headerlink" title="Wireshark解密"></a>Wireshark解密</h3><p>常规办法：</p>
<p>通过设置WSSLKEYLOGFILE进行导出（仅对浏览器有效）</p>
<p>那就会引出下一个问题：我自己写的程序怎么办？</p>
<p>通过导入私钥的办法解决，这个方法用两个限制条件</p>
<ol>
<li>必须要有完整的握手包（Client Hello还有Client Key Exchange，因此TLS版本必须小于1.3）</li>
<li>解密套件仅限于TLS_RSA_开头的Suite</li>
</ol>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://imgse.com/i/pP6q7Yn"><img src="https://s1.ax1x.com/2023/09/09/pP6q7Yn.md.png" alt="pP6q7Yn.md.png"></a></p>
<p>对此，需要对服务端和客户端TLS的config做出修改，添加相关限制</p>
<figure class="highlight go"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">MinVersion:         tls.VersionTLS12,</span><br><span class="line">MaxVersion:         tls.VersionTLS12,</span><br><span class="line">CipherSuites: []<span class="type">uint16</span>&#123;</span><br><span class="line">    tls.TLS_RSA_WITH_AES_128_CBC_SHA,</span><br><span class="line">    tls.TLS_RSA_WITH_AES_256_CBC_SHA,</span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>

<p>满足上述条件即可通过导入私钥抓包</p>
<p><a target="_blank" rel="noopener external nofollow noreferrer" href="https://imgse.com/i/pP6qTFs"><img src="https://s1.ax1x.com/2023/09/09/pP6qTFs.md.png" alt="pP6qTFs.md.png"></a></p>
<p>由此可见，就算是服务器丢了私钥，使用TLS1.3的情况下也无法对数据包解密</p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>Sever最终进入死循环，在循环中接收到conn后转移到goroutine中解决</p>
<p>实现聊天室就需要建立连接池，建一个Map或和Array的全局变量把连接添加进去即可。</p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://www.mocusez.site">MocusEZ</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.mocusez.site/posts/5e44.html">https://www.mocusez.site/posts/5e44.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc/4.0" rel="external nofollow noreferrer" target="_blank">CC BY-NC 4.0</a> 许可协议。转载请注明来自 <a href="https://www.mocusez.site" target="_blank">Mox的笔记库</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://s1.ax1x.com/2023/09/09/pP6qXOU.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/posts/3e9f.html"><img class="prev-cover" src="https://z1.ax1x.com/2023/10/21/piF47TA.md.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">RMM观察与初探</div></div></a></div><div class="next-post pull-right"><a href="/posts/cd44.html"><img class="next-cover" src="https://s1.ax1x.com/2023/09/08/pPyvO0O.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">JQuery的XSS初探</div></div></a></div></nav><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="waline-wrap"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/head.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">MocusEZ</div><div class="author-info__description">探索未曾设想的道路</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">61</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">0</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/mocusez" rel="external nofollow noreferrer" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:285918468@qq.com" rel="external nofollow noreferrer" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="/atom.xml" target="_blank" title="RSS"><i class="fas fa-rss"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">迎接新的明天</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E8%AF%BE%E8%AE%BE%E2%80%94%E2%80%94UDP-x2F-TCP-x2F-TLS-Socket%E5%AE%9E%E9%AA%8C"><span class="toc-number">1.</span> <span class="toc-text">计算机网络课设——UDP&#x2F;TCP&#x2F;TLS Socket实验</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#TCP"><span class="toc-number">1.1.</span> <span class="toc-text">TCP</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#UDP"><span class="toc-number">1.2.</span> <span class="toc-text">UDP</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#TLS"><span class="toc-number">1.3.</span> <span class="toc-text">TLS</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Wireshark%E8%A7%A3%E5%AF%86"><span class="toc-number">1.3.1.</span> <span class="toc-text">Wireshark解密</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">1.4.</span> <span class="toc-text">总结</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/3e9f.html" title="RMM观察与初探"><img src="https://z1.ax1x.com/2023/10/21/piF47TA.md.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="RMM观察与初探"/></a><div class="content"><a class="title" href="/posts/3e9f.html" title="RMM观察与初探">RMM观察与初探</a><time datetime="2023-10-21T04:30:00.000Z" title="发表于 2023-10-21 12:30:00">2023-10-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/5e44.html" title="计算机网络课设——UDP/TCP/TLS Socket实验"><img src="https://s1.ax1x.com/2023/09/09/pP6qXOU.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="计算机网络课设——UDP/TCP/TLS Socket实验"/></a><div class="content"><a class="title" href="/posts/5e44.html" title="计算机网络课设——UDP/TCP/TLS Socket实验">计算机网络课设——UDP/TCP/TLS Socket实验</a><time datetime="2023-09-09T07:10:00.000Z" title="发表于 2023-09-09 15:10:00">2023-09-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/cd44.html" title="JQuery的XSS初探"><img src="https://s1.ax1x.com/2023/09/08/pPyvO0O.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JQuery的XSS初探"/></a><div class="content"><a class="title" href="/posts/cd44.html" title="JQuery的XSS初探">JQuery的XSS初探</a><time datetime="2023-09-08T04:30:00.000Z" title="发表于 2023-09-08 12:30:00">2023-09-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/5862.html" title="生产实习记录"><img src="https://s1.ax1x.com/2023/09/02/pPBH058.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="生产实习记录"/></a><div class="content"><a class="title" href="/posts/5862.html" title="生产实习记录">生产实习记录</a><time datetime="2023-09-02T13:51:00.000Z" title="发表于 2023-09-02 21:51:00">2023-09-02</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/9a9b.html" title="Fedora-CoreOS配置与试用（2023年）"><img src="https://s1.ax1x.com/2023/08/28/pPa8tlF.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Fedora-CoreOS配置与试用（2023年）"/></a><div class="content"><a class="title" href="/posts/9a9b.html" title="Fedora-CoreOS配置与试用（2023年）">Fedora-CoreOS配置与试用（2023年）</a><time datetime="2023-08-28T11:35:00.000Z" title="发表于 2023-08-28 19:35:00">2023-08-28</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2023 By MocusEZ</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener external nofollow noreferrer" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><a href="http://beian.miit.gov.cn/" rel="external nofollow noreferrer"  style="color:#f72b07" target="_blank">闽ICP备2021003009号</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>function loadWaline () {
  function insertCSS () {
    const link = document.createElement("link")
    link.rel = "stylesheet"
    link.href = "https://cdn.jsdelivr.net/npm/@waline/client/dist/waline.min.css"
    document.head.appendChild(link)
  }

  function initWaline () {
    const waline = Waline.init(Object.assign({
      el: '#waline-wrap',
      serverURL: 'https://waline.mocusez.site',
      pageview: ,
      dark: 'html[data-theme="dark"]',
      path: window.location.pathname,
      comment: false,
    }, null))
  }

  if (typeof Waline === 'function') initWaline()
  else {
    insertCSS()
    getScript('https://cdn.jsdelivr.net/npm/@waline/client/dist/waline.min.js').then(initWaline)
  }
}

if ('Waline' === 'Waline' || !false) {
  if (false) btf.loadComment(document.getElementById('waline-wrap'),loadWaline)
  else setTimeout(loadWaline, 0)
} else {
  function loadOtherComment () {
    loadWaline()
  }
}</script></div><script>(function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/1df8ba05.js","daovoice")
</script><script>var isChatBtn = false
daovoice('init', {
  app_id: '1df8ba05',},{
  launcher: { 
     disableLauncherIcon: isChatBtn // 悬浮 ICON 是否显示
  },
});
daovoice('update');

if (isChatBtn) {
  var chatBtnFn = () => {
    var chatBtn = document.getElementById("chat_btn")
    chatBtn.addEventListener("click", function(){
      daovoice('show')
    });
  }
  chatBtnFn()
} else {
  if (false) {
    function chatBtnHide () {
      daovoice('update', {},{
        launcher: { 
        disableLauncherIcon: true // 悬浮 ICON 是否显示
        },
      });
    }
    function chatBtnShow () {
      daovoice('update', {},{
        launcher: { 
        disableLauncherIcon: false // 悬浮 ICON 是否显示
        },
      });
    }
  }
}</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>